package com.project.communitymanagement.common;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ProjectName: epidemic-prevention-backend
 * @Package: com.project.communitymanagement.common
 * @ClassName: GetId
 * @Author: "XGP"
 * @Description:
 * @Date: 2022/04/07 11:29
 * @Version: 1.0
 */
public class GetId {
    private static long tmpID = 0;

    private static boolean tmpIDlocked = false;

    public static long getId()
    {
        long ltime = 0;
        while (true)
        {
            if(tmpIDlocked == false)
            {
                tmpIDlocked = true;
                //当前：（年、月、日、时、分、秒、毫秒）*10000
                ltime = Long.valueOf(new SimpleDateFormat("yyMMddhhmmssSSS").format(new Date()).toString()) * 10000;
                if(tmpID < ltime)
                {
                    tmpID = ltime;
                }
                else
                {
                    tmpID = tmpID + 1;
                    ltime = tmpID;
                }
                tmpIDlocked = false;
                return ltime;
            }
        }
    }

}
